package cn.icanci.loopstack.bic.sdk.burying.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Service;

/**
 * 用例切面
 * @author icanci
 * @since 1.0 Created in 2023/09/27 16:17
 */
@Aspect
@Service
public class UseCaseStartAspect {

    @Around(value = "execution(* *(..)) && @annotation(useCaseStart))", argNames = "point,useCaseStart")
    public Object round(final ProceedingJoinPoint point, UseCaseStart useCaseStart) throws Throwable {
        try {
            ThreadLocalUtils.setUseCase(useCaseStart.useCaseKey());
            ThreadLocalUtils.fillThreadContext(point);
            return point.proceed();
        } finally {
            ThreadLocalUtils.removeUseCase();
        }
    }
}
